import axios from "axios";
import Qs from "qs";
const BASE_URL = "http://47.98.137.213:8083/wqshop/";
// 添加请求拦截器
const instance = axios.create({
  baseURL: BASE_URL,
  timeout: 1000 * 20,
  headers: {
    "Content-Type": "application/x-www-form-urlencoded",
    Accept: "application/json"
  }
});
// http request 拦截器
instance.interceptors.request.use(
  async config => {
    config.data = Qs.stringify(config.data);
    // config.headers["token"] = userInfo.token || "";
    // console.log("config配置:", config, Qs.stringify(config.data));
    return config;
  },
  err => {
    this.$Message.error("请求失败" + err.message);
    return Promise.reject(err);
  }
);

// http response 拦截器
instance.interceptors.response.use(
  response => {
    const { data } = response;
    console.log("response:", response);
  },
  err => {
    if (err) {
      // RootStore.setLoading(false);
      this.$Message.error("接口出错了,请检查");
    }
  }
);

// 请求处理
export default instance;
